package com.zaizai.controller;

import java.util.List;


import com.zaizai.domain.AjaxResult;
import com.zaizai.domain.CommodityPrice;
import com.zaizai.service.ICommodityPriceService;
import com.zaizai.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.zaizai.domain.AjaxResult.success;


/**
 * 商品日期单价Controller
 *
 * @author zaiZai
 * @date 2024-10-21
 */

@RestController
@RequestMapping("/price")
public class CommodityPriceController extends BaseController {
    @Autowired
    private ICommodityPriceService commodityPriceService;

/**
 * 查询商品日期单价列表
 */

@GetMapping("/list")
    public TableDataInfo list(CommodityPrice commodityPrice) {
        startPage();
        List<CommodityPrice> list = commodityPriceService.selectCommodityPriceList(commodityPrice);
        return getDataTable(list);
    }

    /**
     * 获取商品日期单价详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(commodityPriceService.selectCommodityPriceById(id));
    }

    /**
     * 新增商品日期单价
     */

    @PostMapping
    public AjaxResult add(@RequestBody CommodityPrice commodityPrice) {
        return success(commodityPriceService.insertCommodityPrice(commodityPrice));
    }

    /**
     * 修改商品日期单价
     */

    @PutMapping
    public AjaxResult edit(@RequestBody CommodityPrice commodityPrice) {
        return success(commodityPriceService.updateCommodityPrice(commodityPrice));
    }

    /**
     * 删除商品日期单价
     */

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(commodityPriceService.deleteCommodityPriceByIds(ids));
    }
}
